import { Injectable } from '@angular/core';
import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';

@Injectable({
  providedIn: 'root',
})
export class StroageService {
  constructor(private localStorageService: LocalStorageService) {}
  getData(): Promise<TaomeiObj> {
    return new Promise((res, rej) => {
      res({
        textFontSize: this.localStorageService.retrieve('textFontSize') || 22,
        fixedTextFontSize:
          this.localStorageService.retrieve('fixedTextFontSize') || 22,
        textFontBlod: this.localStorageService.retrieve('textFontBlod') || '1',
        textFontColor:
          this.localStorageService.retrieve('textFontColor') || '#000',
        fixedTextFontColor:
          this.localStorageService.retrieve('fixedTextFontColor') || '#000',
        textShadowSize1:
          this.localStorageService.retrieve('textShadowSize1') || 0,
        textShadowSize2:
          this.localStorageService.retrieve('textShadowSize2') || 0,
        textShadowSize3:
          this.localStorageService.retrieve('textShadowSize3') || 0,
        textShadowColor:
          this.localStorageService.retrieve('textShadowColor') || '#FFF',
        fixedTextShadowSize1:
          this.localStorageService.retrieve('fixedTextShadowSize1') || 0,
        fixedTextShadowSize2:
          this.localStorageService.retrieve('fixedTextShadowSize2') || 0,
        fixedTextShadowSize3:
          this.localStorageService.retrieve('fixedTextShadowSize3') || 0,
        fixedTextShadowColor:
          this.localStorageService.retrieve('fixedTextShadowColor') || '#FFF',
        scrollSpeed: this.localStorageService.retrieve('scrollSpeed') || 5000,
        hasBg: this.localStorageService.retrieve('hasBg') || '1',
        fixedText:
          this.localStorageService.retrieve('fixedText') || '游戏名:炉石传说',
        carouselText: this.localStorageService.retrieve('carouselText') || [
          [
            { label: '直播间赠送超级水晶' },
            { label: '戒指钥匙触发超级宝箱' },
            { label: '主播会奖励2万 RMB' },
          ],
          [
            { label: '新浪微博:炉石涛妹' },
            { label: '水友Q群:461614988' },
            { label: '(投稿具体看群公告)' },
          ],
          [
            { label: '投稿:314515657@qq.com' },
            { label: '如果采纳会有60元稿费' },
          ],
        ],
      });
    });
  }
  setData(taomeiObj: TaomeiObj) {
    this.localStorageService.store('textFontSize', taomeiObj.textFontSize);
    this.localStorageService.store(
      'fixedTextFontSize',
      taomeiObj.fixedTextFontSize,
    );
    this.localStorageService.store('textFontBlod', taomeiObj.textFontBlod);
    this.localStorageService.store('textFontColor', taomeiObj.textFontColor);
    this.localStorageService.store(
      'fixedTextFontColor',
      taomeiObj.fixedTextFontColor,
    );
    this.localStorageService.store(
      'textShadowSize1',
      taomeiObj.textShadowSize1,
    );
    this.localStorageService.store(
      'textShadowSize2',
      taomeiObj.textShadowSize2,
    );
    this.localStorageService.store(
      'textShadowSize3',
      taomeiObj.textShadowSize3,
    );
    this.localStorageService.store(
      'textShadowColor',
      taomeiObj.textShadowColor,
    );
    this.localStorageService.store(
      'fixedTextShadowSize1',
      taomeiObj.fixedTextShadowSize1,
    );
    this.localStorageService.store(
      'fixedTextShadowSize2',
      taomeiObj.fixedTextShadowSize2,
    );
    this.localStorageService.store(
      'fixedTextShadowSize3',
      taomeiObj.fixedTextShadowSize3,
    );
    this.localStorageService.store(
      'fixedTextShadowColor',
      taomeiObj.fixedTextShadowColor,
    );
    this.localStorageService.store('scrollSpeed', taomeiObj.scrollSpeed);
    this.localStorageService.store('hasBg', taomeiObj.hasBg);
    this.localStorageService.store('fixedText', taomeiObj.fixedText);
    this.localStorageService.store('carouselText', taomeiObj.carouselText);
  }
}
export interface TaomeiObj {
  textFontSize: number;
  fixedTextFontSize: number;
  textFontBlod: string;
  textFontColor: string;
  fixedTextFontColor: string;
  textShadowSize1: number;
  textShadowSize2: number;
  textShadowSize3: number;
  textShadowColor: string;
  fixedTextShadowSize1: number;
  fixedTextShadowSize2: number;
  fixedTextShadowSize3: number;
  fixedTextShadowColor: string;
  scrollSpeed: number;
  hasBg: string;
  fixedText: string;
  carouselText: Array<Array<any>>;
}
